import Fun
# TreeView作为表格使用时的相关操作
def addItem(uiName,TreeViewName,*item):
    treeview = Fun.GetElement(uiName,TreeViewName)
    treeview.insert('', 'end', values=(item[0], item[1], item[2], item[3], item[4], item[5]))
def editSelected(uiName,TreeViewName,*item):
    treeview = Fun.GetElement(uiName,TreeViewName)
    index = treeview.selection()
    if(len(index) == 0):
        return None
    colNames =["设备类型","设备名称","设备串口","波特率","备注"]
    for i in range(0,len(colNames)):
        treeview.set(index, colNames[i], item[i])

    return treeview.item(index)['values']
def deleteSelected(uiName,TreeViewName):
    treeview = Fun.GetElement(uiName,TreeViewName)
    index = treeview.selection()
    if(len(index) == 0):
        return None
    item = treeview.item(index)
    treeview.delete(index)
    return item['values']
def getSelected(uiName,TreeViewName):
    treeview = Fun.GetElement(uiName,TreeViewName)
    index = treeview.selection()
    if(len(index) == 0):
        return None
    return treeview.item(index)['values']
def clearData(uiName,TreeViewName):
    treeview = Fun.GetElement(uiName,TreeViewName)
    obj = treeview.get_children()
    for i in obj:
        treeview.delete(i)
    return treeview